package org.example.ExperimentTwo;

import java.util.*;

public class StudentScore {
    public static void main(String[] args) {
        String string="";
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入string：");
        string=sc.next();
//        创建people的list对象
        List<Person> people=new ArrayList<>();
//        对string进行处理
        String[] peoplestring=string.split("\\|");
//        遍历peoplestring[]
        for (String person: peoplestring
             ) {
              String[] parts=person.split(":");
//              分出姓名年龄成绩
              String name=parts[0];
              int age=Integer.parseInt(parts[1]);
            double score = Double.parseDouble(parts[2]);
            Person person1=new Person(name, age, score);
            people.add(person1);
        }
//        添加排序方法
        Collections.sort(people, new Comparator<Person>() {
            @Override
            public int compare(Person p1, Person p2) {
                if (p1.getScore() != p2.getScore()) {
                    // 按照成绩由高到低排序
                    return Double.compare(p2.getScore(), p1.getScore());
                } else {
                    // 成绩相同，则按照年龄由小到大排序
                    return Integer.compare(p1.getAge(), p2.getAge());
                }
            }
        });
        for (Person person:
             people) {
//            System.out.println(person);
            System.out.print("Student"+"["+person+"],");
        }
    }
}
